<!--头部公共部分-->
{include file="common/header" /}
<style>
    #editStudentInfo {
        display: inline-block;
        width: 13px;
        height: 19px;
        background: url(/education/images/conctractIcon.png) no-repeat bottom;
        cursor: pointer;
        background-position: -194px -7px;
    }
</style>

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite><span class="x-red" style="font-size: 14px;">(订单号-{$contract.contract_number}&nbsp;&nbsp;&nbsp;校区-{$campus_name})</span></cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" id="backlist_head"  style="margin-top:7px;float:right;margin-left: 10px;">返回订单管理页面</a>

</div>
<div style="padding:15px;">
    <div style="padding:15px;">学员信息</div>
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">学员姓名</label>
                <div class="layui-form-mid layui-word-aux">{$student.student_name}</div>
                <div class="layui-form-mid layui-word-aux"><i id="editStudentInfo"></i></div>
                <input type="hidden" name="id" value="{$student.id}">
                <input type="hidden" name="student_name" value="{$student.student_name}">
                <input type="hidden" name="student_number" value="{$student.student_number}">
                <input type="hidden" name="student_number" value="{$student.student_number}">
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学员年级</label>
                <div class="layui-form-mid layui-word-aux">{$student.grade}</div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-form-mid layui-word-aux">{$student.phone}</div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学校班级</label>
                <div class="layui-form-mid layui-word-aux">{$student.school_class}</div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">来源渠道</label>
                <div class="layui-form-mid layui-word-aux">{$student.channel}</div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学员生日</label>
                <div class="layui-form-mid layui-word-aux">{$student.birth}</div>
            </div>
        </div>
    </form>
</div>
<div style="padding:15px;">
    <div style="padding:15px;">报读项目</div>
    <form class="layui-form">
        <div class="layui-form-item">

            <table class="layui-table" style="width:100%" id="showTb">
                <thead>
                <tr>
                    <th style="text-align: center; font-size: 12px">报名项目</th>
                    <th style="text-align: center; font-size: 12px">单价(元)</th>
                    <th style="text-align: center; font-size: 12px">数量</th>
                    <th style="text-align: center; font-size: 12px">折扣比例(%)</th>
                    <th style="text-align: center; font-size: 12px ">直减金额</th>
                    <th style="text-align: center; font-size: 12px">折后应收</th>
                    <th style="text-align: center; font-size: 12px">赠送数量</th>
                    <th style="text-align: center; font-size: 12px ">是否分摊</th>
                    <th style="text-align: center; font-size: 12px">签约类型</th>
                    <th style="text-align: center; font-size: 12px">分配座位</th>
                </tr>
                </thead>
                <tbody id="xq">
                <script>
                    var jsondata = eval('{$json_data}');
                    console.log("jsondata:"+jsondata.length)
                    console.log(jsondata)
                    for(var i =0; i < jsondata.length; i ++){
                        document.write('<tr>');
                        document.write('<td style="text-align: center; font-size: 10px">'+jsondata[i].project_name+'</td>');
                        document.write('<td style="text-align: center; font-size: 10px">'+jsondata[i].project_price+'</td>');
                        document.write('<td style="text-align: center; font-size: 10px"><input type="hidden" name="arr_pos_nums" value='+ i +'><input type="number" min="0" readonly name="project_nums"  autocomplete="off" value="'+ jsondata[i].project_num +'" class="layui-input"></td>');
                        document.write('<td style="text-align: center; font-size: 10px"><input type="hidden" name="arr_pos_rate" value='+ i +'><input type="number" min="0" readonly max="100" name="project_rate"  autocomplete="off" value="'+ jsondata[i].project_rate +'" class="layui-input"></td>');
                        document.write('<td style="text-align: center; font-size: 10px"><input type="hidden" name="arr_pos_direct" value='+ i +'><input type="number" readonly name="project_direct" min="0" autocomplete="off" value="'+ jsondata[i].project_direct_money +'" class="layui-input"></td>');
                        document.write('<td style="text-align: center; font-size: 10px"><input type="hidden" name="arr_pos_price" value='+ i +'><input type="number" readonly min="0"  autocomplete="off"  name="project_net_receipts"  value="'+ jsondata[i].project_net_receipts +'" class="layui-input"></td>');
                        if(jsondata[i].project_type == 2 || jsondata[i].project_type == 1){
                            document.write('<td style="text-align: center; font-size: 10px"><input type="hidden" name="arr_pos_give" value='+ i +'><input type="number" readonly min="0" name="project_give_nums" autocomplete="off" value="'+ jsondata[i].project_give_class_num +'" class="layui-input"></td>');
                        }else{
                            document.write('<td style="text-align: center; font-size: 10px">--</td>');
                        }
                        if(jsondata[i].project_assessed_status == 0){
                            document.write('<td style="text-align: center; font-size: 10px"><input type="checkbox" name="share_box" value="'+ i +'" lay-filter="share_filter" lay-skin="primary" disabled></td>');
                        }else{
                            document.write('<td style="text-align: center; font-size: 10px"><input type="checkbox" name="share_box" value="'+ i +'" lay-filter="share_filter" lay-skin="primary" checked disabled></td>');
                        }
                        let contract_type =  jsondata[i].project_contract_type;
                        if(contract_type == 127){
                            document.write('<td style="text-align: center; font-size: 10px"><select lay-verify="required" name="contract_type_filter"  lay-filter="contract_type_filter" disabled><option value="-1"></option><option value="127-'+ i +'" selected>新签</option> <option value="128-'+ i +'">续费</option> <option value="129-'+ i +'">扩科</option></select></td>');
                        }else if(contract_type == 128){
                            document.write('<td style="text-align: center; font-size: 10px"><select lay-verify="required" name="contract_type_filter" lay-filter="contract_type_filter" disabled><option value="-1"></option><option value="127-'+ i +'">新签</option> <option value="128-'+ i +'" selected>续费</option> <option value="129-'+ i +'">扩科</option></select></td>');
                        }else if(contract_type == 129){
                            document.write('<td style="text-align: center; font-size: 10px"><select lay-verify="required" name="contract_type_filter" lay-filter="contract_type_filter" disabled><option value="-1"></option><option value="127-'+ i +'">新签</option> <option value="128-'+ i +'">续费</option> <option value="129-'+ i +'" selected>扩科</option></select></td>');
                        }else{
                            document.write('<td style="text-align: center; font-size: 10px"><select lay-verify="required" name="contract_type_filter" lay-filter="contract_type_filter" disabled><option value="-1"></option><option value="127-'+ i +'">新签</option> <option value="128-'+ i +'">续费</option> <option value="129-'+ i +'">扩科</option></select></td>');
                        }

                        if(jsondata[i].project_type == 1){
                            if(jsondata[i].project_seat == 1){
                                document.write('<td style="text-align: center; font-size: 10px" onclick="Set_Project_seat(this)"><input type="hidden" name="arr_pos_seat" value='+ i +'><span style="cursor: pointer;color: red; font-weight: bold;">已选座</span></td>');
                            }else{
                                document.write('<td style="text-align: center; font-size: 10px" onclick="Set_Project_seat(this)"><input type="hidden" name="arr_pos_seat" value='+ i +'><img style="cursor: pointer" src="/seat.jpg" width="20" height="20"></td>');
                            }
                        }else{
                            document.write('<td style="text-align: center; font-size: 10px">--</td>');
                        }
                        document.write('</tr>');
                    }

                </script>
                </tbody>
            </table>

            <input type="hidden"  id="room_id">
            <input type="hidden"  id="room_name">
        </div>

    </form>
</div>
<fieldset class="layui-elem-field layui-field-title">
    <legend>结算</legend>
</fieldset>
<div class="layui-tab">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span style="color: red;">*</span>签约人</label>
                        <div class="layui-input-inline">
                            <select  disabled="disabled" lay-verify="required" lay-search="">
                                {volist name="user" id="v"}
                                <option value="{$v.id}" {if $contract.contractor == $v.id}selected{/if}>{$v['name']}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span style="color: red;">*</span>录入类型</label>
                        <div class="layui-input-inline">
                        <input type="text"   value="{$contract.input_type_text}" autocomplete="off"  placeholder="录入类型" readonly class="layui-input">
                        </div>
                        </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span style="color: red;">*</span>签约日期</label>
                        <div class="layui-input-inline">
                            <input type="text"  id="date" name="signing_date" value="{$contract.signing_date}" readonly lay-verify="required" placeholder="签约日期" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">对外备注</label>
                    <div class="layui-input-block">
                        <textarea name="out_remark" placeholder="此备注将打印在订单上" class="layui-textarea">{$contract.out_remark}</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">对内备注</label>
                    <div class="layui-input-block">
                        <textarea name="in_remark" placeholder="此备注不会打印在订单上，工作人员可在订单列表查看" class="layui-textarea">{$contract.in_remark}</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">优惠方案</label>
                    <div class="layui-inline">

                        <!--
                        <input type="radio" name="discount_modle" lay-filter="radio_modle" value="1" title="先折扣后直减"checked>
                        <input type="radio" name="discount_modle" lay-filter="radio_modle" value="2" title="先直减后折扣">
                        -->
                      <script>
                          var discount_modle = parseInt('{$contract.discount_modle}');
                          if(discount_modle === 1){
                            document.write('<input type="radio"   value="1" title="先折扣后直减"checked disabled>');
                              document.write('<input type="radio"  value="2" title="先直减后折扣" disabled>');
                          }else if(discount_modle === 2){
                              document.write('<input type="radio"   value="1" title="先折扣后直减" disabled>');
                              document.write('<input type="radio"  value="2" title="先直减后折扣"checked disabled>');
                          }

                      </script>

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">结算</label>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">直减优惠</div>
                        <div class="layui-input-inline">
                            <input type="number" id="youhui" name="direct_discount" readonly value="{$contract.direct_discount}"  min="0" placeholder="0" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">元</div>
                    </div>

                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux"  name="discount_rate" style="font-size: 12px; margin-left: 55px;">折扣比率</div>
                        <div class="layui-input-inline">
                            <input type="number" id="rate" readonly min="0" max="100" value="{$contract.discount_rate}"    placeholder="0" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">%</div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">抵扣</label>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">使用积分</div>
                        <div class="layui-input-inline">
                            <input type="text"  id="integral" name="integrals"   value="{$contract.integrals}" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">(可抵扣学费)</div>
                    </div>

                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">优惠券码</div>
                        <div class="layui-input-inline">
                            <input type="text" id="discount_code" value="" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">(可抵扣学费)</div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">合计</label>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux"  style="font-size: 12px;">订单总计</div>
                        <div class="layui-input-inline">
                            <input type="text" id="total_amount"  name="total_amount" value="{$contract.total_amount + $contract.preferential}" readonly placeholder="" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">元</div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px; margin-left: 55px;">优惠总计</div>
                        <div class="layui-input-inline">
                            <input type="text"name="preferential"  id="yh" readonly placeholder="0" value="{$contract.preferential}" readonly  autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">元</div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-form-mid layui-word-aux" name="stay_amount" style="font-size: 12px;">订单应收款</div>
                        <div class="layui-input-inline">

                            <input type="text"  id="yingshou" value="{$contract.total_amount}" readonly placeholder=""  autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux" style="font-size: 12px;">元</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="id" value="{$contract.id}">
                        <input class="layui-btn" lay-submit lay-filter="wxsubmit"  id="sub" value="保存订单" readonly>
                        <a class="layui-btn layui-btn-primary" id="backlist">返回</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>


    let layer_;
    layui.use(['jquery','form','layer','element','table', 'laydate'], function(){
        var $ = layui.jquery,
            layer = layui.layer,
            laydate = layui.laydate,
            table = layui.table,
            element = layui.element,
            form = layui.form;

        layer_ = layui.layer,

            //日期
        laydate.render({
            elem: '#date',
            type: 'date'
            ,trigger: 'click'
        });

        let id = '{$contract.id}';
        let campus_id = '{$contract.campus_id}';






        $('#editStudentInfo').click(function () {
            var id = $('input[name=id]').val();
            var student_name = $('input[name=student_name]').val();
            var student_number = $('input[name=student_number]').val();
            var url = "{:url('student/edit')}?id=" + id + '&type=' + 101;
            layer.open({
                type: 2,
                title: student_name + '    ' + '(' + '学员编号:    ' + student_number + ')',
                shadeClose: true,
                shade: 0.5,
                area: ['90%', '98%'],
                content: url
            });
        });

        form.on('submit(wxsubmit)', function (data) {
            var field = data.field;
            field['id'] = '{$contract.id}'; //传递订单自增id
            field.campus_id = '{$contract.campus_id}';
            let cid = '{$contract.id}';
            let campus_id = '{$contract.campus_id}';
            $.ajax({
                url: '{:url("Contract/wxsubmit_update_status")}',
                method: "post",
                data: {cid: cid, campus_id: campus_id},
                success: function (result) {
                    console.log(result);
                    if (result.code === 1) {
                        $.ajax({
                            type: 'post',
                            url: '{:url("contract/edit")}',
                            data: field,
                            success: function (result) {
                                if (result.code === 0) {
                                    layer.msg(result.msg, {time: 2000});
                                    setTimeout(function () {
                                        location.href = '{:url("contract/lists")}';
                                    }, 2000)
                                }else {
                                    layer.msg(result.msg, {time: 2000});
                                }

                            }
                        });
                    }
                },
            });




        });

        /**********返回**********/
        $('#backlist').click(function () {
            let cid = '{$contract.id}';
            let campus_id = '{$contract.campus_id}';
            $.ajax({
                url: '{:url("Contract/edit_backcontract_lists")}',
                method: "post",
                data: {cid: cid, campus_id: campus_id},
                success: function (result) {
                    console.log(result);
                    if (result.code === 1) {
                        location.href = "{:url('contract/lists')}";
                    }
                },
            });


        });

        /**********返回**********/
        $('#backlist_head').click(function () {
            let cid = '{$contract.id}';
            let campus_id = '{$contract.campus_id}';
            $.ajax({
                url: '{:url("Contract/edit_backcontract_lists")}',
                method: "post",
                data: {cid: cid, campus_id: campus_id},
                success: function (result) {
                    console.log(result);
                    if (result.code === 1) {
                        location.href = "{:url('contract/lists')}";
                    }
                },
            });


        });

    });
    //座位设置
    function setClass_id(id,room_name) {
        $("#room_id").val(id);
        $("#room_name").val(room_name);

    }
    function Set_Project_seat(obj) {
        var arr_pos_seat = $(obj).find("input[name='arr_pos_seat']").val();
        layer_.open({
            type: 2,
            skin: 'layui-layer-lan',
            closeBtn: 2,
            title: '选择教室选座',
            // btn: ['确定', '取消'],
            area: ['30%', '40%'],
            shadeClose: false,
            content: "{:url('Grades/choice_room')}?id=" + jsondata[arr_pos_seat].project_info_id,
            end:function () {

                var room_id = $("#room_id").val();
                var room_name =     $("#room_name").val();
                if(room_id == '' || room_id.length <= 0 || room_name == '' || room_name <= 0){
                    return;
                }
                var url = '{:url("Customer/seat_selection")}?id='+room_id + '&class_subject_id='+jsondata[arr_pos_seat].project_info_id + "&campus_id=" + jsondata[arr_pos_seat].project_campus_id + '&grades_contract_id=' + jsondata[arr_pos_seat].project_id + '&edit_type=' + 1;
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '【'+room_name+'】'+'---'+'选座',
                    area: ['80%', '80%'],
                    shadeClose: false,
                    content: url,
                    cancel: function(index, layero){
                        location.reload();

                        return false;
                    }
                });


            }
        });
    }

</script>
